import json
import urllib.request
import urllib.parse

url = 'https://fanyi.baidu.com/v2transapi?from=en&to=zh'
header = {
    'Accept': '*/*',
    # 'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Acs-Token': '1698753509580_1698753508384_bK7UQNPSLNetKjZ2R2hqShwpH8XGs1dpZW3xhEyTPjzX34viDotMZgMZPJ9t0q046MfwPxIXzm1bvm0qZ8ZhaeQl89yBjRwOaHKredq/JVWMJxr35oE1uotswzr76rOvpp8lPxO4c+BRt+u834pZpiQVGxpFAzlvrU3OZRe7+0oC+8zS2dR5Q6wgwJInYidgB6hfXkICkfZTqfgri5GCwMh3FW9uNg+31A8FRC1LmsjZqzhlg7emIH8VUFl78/HNtS2niIp+PCknueB8Udu/9ish2/en7sAtCbVgXyXvnE0ETFIGG118shnZPCcrNPX+6qTqJfRZAURjyKWMy2GcVCuwZalmXVTnv6RXvJJu7xuvX3/lbvEuWfPJbNButoq3h9t3X/94uX/NaTLWQQnQFOveL/x3925XxohTVol3DW8FOsvxKg1tKxEpVgKodEXwfDEm4UROrA/oVgWHdEmMgOB8FFyquT97Cq/NYMgOVaSEpwGzX7/KMSvSSiN5Ut3M4QJOgRepLWmuRrgJ4Db05w==',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Length': '130',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'BAIDUID=2E7448FA0AE22FAD41F798DA84E0B4F2:FG=1; BIDUPSID=2E7448FA0AE22FAD41F798DA84E0B4F2; PSTM=1682681731; BDUSS=3Y3NFVScmRlR3FzWjJDMkZJaEl-SDR0QW50UlR6eUV6cWM5OUFSakJvYWRQTkprSVFBQUFBJCQAAAAAAAAAAAEAAAC8s7CX7M~Oss6yAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ2vqmSdr6pkZ; BDUSS_BFESS=3Y3NFVScmRlR3FzWjJDMkZJaEl-SDR0QW50UlR6eUV6cWM5OUFSakJvYWRQTkprSVFBQUFBJCQAAAAAAAAAAAEAAAC8s7CX7M~Oss6yAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ2vqmSdr6pkZ; BAIDUID_BFESS=2E7448FA0AE22FAD41F798DA84E0B4F2:FG=1; BAIDU_WISE_UID=wapp_1696013201973_265; ZFY=lNeXIQHPLwPfcON:AvDrOUgtBoIOW77bkUX1ZrlUfz0A:C; RT="z=1&dm=baidu.com&si=9a29f03c-e8c8-453c-af34-070eabec9368&ss=lo9wk49b&sl=2t&tt=t56&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=3h7r3&ul=8521c&hd=8523n"; __bid_n=18b8574485e531279ac5b6; BA_HECTOR=ag0k2la5248g808581a4akah1ik1oja1r; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; PSINO=7; delPer=0; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_PS_PSSID=39445_39396_39531_39418_39142_39439_39523_39521_39497_26350_39561_22157; BCLID=11535887696267118712; BCLID_BFESS=11535887696267118712; BDSFRCVID=ovkOJexroG3O1Hvq8yIbUr4upFweG7bTDYrEOwXPsp3LGJLVFdWiEG0Pts1-dEu-S2OOogKK3gOTH4DF_2uxOjjg8UtVJeC6EG0Ptf8g0M5; BDSFRCVID_BFESS=ovkOJexroG3O1Hvq8yIbUr4upFweG7bTDYrEOwXPsp3LGJLVFdWiEG0Pts1-dEu-S2OOogKK3gOTH4DF_2uxOjjg8UtVJeC6EG0Ptf8g0M5; H_BDCLCKID_SF=tRAOoC_-tDvDqTrP-trf5DCShUFstq_jB2Q-XPoO3KOchqnCKj7BKMCAKGOtbU5f5mkf3fbgy4op8P3y0bb2DUA1y4vp0t3U2mTxo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MzMjQ1NTA0MDgwNmY0Mjg3YTI5NzU0Yzg4M2FkMWU2Yzhk',
    'Host': 'fanyi.baidu.com',
    'Origin': 'https://fanyi.baidu.com',
    'Pragma': 'no-cache',
    'Referer': 'https://fanyi.baidu.com/translate?query=p&lang=auto2zh',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.76',
    'X-Requested-With': 'XMLHttpRequest',
    'sec-ch-ua': '"Chromium";v="118", "Microsoft Edge";v="118", "Not=A?Brand";v="99"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}
data = {
    'from': 'en',
    'to': 'zh',
    'query': 'p',
    'simple_means_flag': '3',
    'sign': '259913.463992',
    'token': '9add4a756a197ea363332ad4ab9069df',
    'domain': 'common',
    'ts': '1698753508357'
}

data = urllib.parse.urlencode(data).encode('utf-8')
request = urllib.request.Request(url=url,data=data,headers=header)
response = urllib.request.urlopen(request)
content = response.read().decode('utf-8')
obj = json.loads(content)
print(obj)